<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="/lib/haha/core/start.js"></script>
    <script type="text/javascript" src="lib/layDate-v5.0.9/layDate-v5.0.9/laydate/laydate.js"></script>
    <link rel="stylesheet" href="CSS/pageNation.css">
    <link rel="stylesheet" href="CSS/advanceSearch.css">
    <link rel="stylesheet" href="CSS/knowledge.css">
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
</head>

<body>
    <div id="header"></div>
    <!-- 内容 -->
    <div class="container">
        <!-- 左侧菜单 -->
        <div class="aside">
            <div class="top">
                <div class="left bg_size">
                    <span>数据来源</span>
                </div>
                <div class="right">
                    <span class="select" id="all">全选</span>
                    <span class="two" id="not">取消</span>
                </div>
            </div>
            <!-- 分类导航栏菜单 -->
            <div class="asideMenu" id='asideMenu'>
            </div>
        </div>
        <!-- 右侧表格 -->
        <div class="content">
            <!-- 搜索框 -->
            <div class="searchBox flex" id='search_content'>
                <!-- 搜索 -->
                <div class="searchPart flex" id='search'>
                </div>
                <!-- 高级检索 -->
                <button class="borderNone a_Btn" id='advance'>高级检索</button>
            </div>
            <!-- 表格 -->
            <!-- 头部 -->
            <!-- 高级检索 -->
            <div id='advanceSearch' style="display: none;"></div>
            <div class="tbHeader">
                <div class="head flex-start">
                    <span>排序：</span>
                    <ul class="flex-start">
                        <li>
                            <span class='RELEVANT'>相关性</span>
                            <div>
                                <button class="bottom" value=""></button>
                            </div>

                        </li>
                        <li>
                            <span class='发表时间'>发表时间</span>
                            <div>
                                <button class="top" value="ASC"></button>
                                <button class="bottom" value="DESC"></button>
                            </div>
                        </li>
                        <li>
                            <span class='下载频次'>下载量</span>
                            <div>
                                <button class="top" value="ASC"></button>
                                <button class="bottom" value="DESC"></button>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
            <!-- 表格数据 -->
            <div class="tableData" id='knowledgeTable'>
                <span id='KnowledgeMention' style="display: none;text-align: center;padding: 20px 0;">暂无数据</span>
                <div style="min-height: 540px;overflow: hidden;">
                    <table>
                        <script id='knowledgeTableData' type="text/html">
                        <tr>
                            <td class="one"> <span class='num'>{{:#data['num']}}</span></td>
                            <td class="two">
                                <p class="title hover" data-tablename='{{:~tableName(#data,#index)}}' data-dbsource='{{:#data["dbsource"]}}' data-sysid='{{:#data["sysID"]}}'  title='{{:#data["tansTitle"]}}' data-filename='{{:#data["fileName"]}}' data-title='{{:#data["tansTitle"]}}'>{{:#data['title']}}</p>
                                <ul class="flex-wrap">
                                    <li><span>发布时间：</span><span>{{:#data['publishDate'].split(' ')[0]}}</span></li>
                                    <li><span>数据来源：</span>
                                    {{if dbsource}}
                                        <span class="red" title="{{:#data['dbsource']}}">{{:#data['dbsource']}} </span>
                                    {{else}}
                                    <span class="red" title="{{:#data['tableName']}}">{{:#data['tableName']}} </span>
                                    {{/if}}
                                    </li>
                                    <li><span>下载量：</span><span>{{:#data['downRate']}}</span></li>
                                    <li style="position: absolute;right: -100px;top:0px">
                                        <ul class="flex-start" >
                                            <li class="save" style="{{:~hideSave(#data,#index)}}"  data-tablename='{{:~tableName(#data,#index)}}'  data-dbsource='{{:#data["dbsource"]}}' data-dbname='{{:#data["dbsource"]}}' data-sysid='{{:#data["sysID"]}}'  data-filename='{{:#data["fileName"]}}'   data-title='{{:#data["tansTitle"]}}' data-ipAddress="{{:~ipAddress(#data,#index)}}"><span class="saveImg"></span>
                                            </li>
                                            <li class="preview" style="{{:~showSave(#data,#index)}}"   data-dbsource='{{:#data["dbsource"]}}' data-dbname='{{:#data["dbsource"]}}' data-tablename='{{:#data["tableName"]}}' data-sysid='{{:#data["sysID"]}}' data-digitfilename='{{:#data["digitFileName"]}}'><span class="previewImg"></span>
                                            </li>
                                            <li class="download" style="{{:~showSave(#data,#index)}}"   data-dbsource='{{:#data["dbsource"]}}'  data-dbname='{{:#data["dbsource"]}}'  data-tablename='{{:#data["tableName"]}}'  data-dbsource='{{:#data["dbsource"]}}' data-sysid='{{:#data["sysID"]}}'  data-filename='{{:#data["fileName"]}}'  data-ipAddress="{{:~ipAddress(#data,#index)}}"  data-title='{{:#data["tansTitle"]}}' data-digitfilename='{{:#data["digitFileName"]}}'><span class="downLoadImg"></span>
                                            </li>

                                        </ul>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                        </script>
                        <!-- 暂无数据 -->
                    </table>
                </div>
                <!-- 分页 -->
                <div class="pageNation">
                    <div id="test1"></div>
                </div>
            </div>
        </div>
    </div>
    <!-- 脚部 -->
    <div id="footer"></div>
    <!-- 收藏弹窗 -->
    <div id='saveClassify' class='saveClassify' style="display: none;"></div>
    <script type="text/javascript">
        shared.useLayout("act-1");
        // 侧边多选菜单栏
        $("#asideMenu").load("/shared/selectMenu.html");
    </script>
    <script type="text/javascript" src="/lib/layer-v3.1.1/layer/layer.js"></script>
    <script src="/lib/layui/layui.js"></script>
    <script>
        var postTableData = {
            searchKeyWord: '',
            searchValue: '',
            // 当前页
            page: 1,
            // 每页显示条数
            pageSize: 20,
            //高级检索词
            conditionSql: "",
            beginDate: "",
            endDate: "",
            limitData: "",
            orderBySort: "",
            orderByValue: "",
            standConditionBoList: '',
        }
        var searchType = 'search';
        var lastAdvancedSearchStr = '';
        var isOutList = [];
        //按回车调取检索函数
        var callBackPage = function callBack(curr, limit) {
        };
        function goMultiSearch() {
            clearSort();
            // $('.tbHeader button').eq(0).addClass('clickBottom');
            // 清空高级检索 ie8不支持默认参数
            postTableData.conditionSql = '';
            postTableData.beginDate = "";
            postTableData.endDate = "";
            postTableData.limitData = '';
            postTableData.page = 1;
            // 清除排序
            postTableData.orderBySort = "",
                postTableData.orderByValue = "",
                //清除高级检索的在结果中检索
                lastAdvancedSearchStr = '';
            // 如果路由有参数
            changeValue();
            pageData.tableData(config.complexSearch, postTableData, 'knowledgeTableData', 'test1', true, '#KnowledgeMention', render(), true, callBackPage);
        }
        function getMenu() {
            //选择选中的值
            var list = []
            $('.hasChildren .check').each(function (index, item) {
                var childrenList = [];
                if (!JSON.parse($(item).parent('p').attr('data-status'))) {
                    $(item).parent('p').next('ul').find('.check').each(function (index, item1) {
                        childrenList.push($(item1).parent('p').attr('data-dbcode'))
                    })
                    list.push({ 'dbCode': $(item).parent('p').attr('data-dbcode'), "classifyCodes": childrenList.length ? childrenList : null })
                } else {
                    $(item).parent('p').next('ul').find('.check').each(function (index, item1) {
                        list.push({ 'dbCode': $(item1).parent('p').attr('data-dbcode'), "classifyCodes": $(item1).parent('p').attr('data-classifyCodes') || null })
                    })
                }
            })
            $('.noChildren .check').each(function (index, item) {
                var childrenList = [];
                list.push({ 'dbCode': $(item).parent('p').attr('data-dbcode'), "classifyCodes": null })

            })
            return list;
        }
        function render(data, index) {
            return {
                showSave: function (data, index) {
                    if (data.tableName == "YQTQBZX_METADATA") {
                        return 'display:none';
                    }
                    else if (data.tableName == "YQTFZWW_METADATA") {
                        return 'display:none';
                    }
                    for (let i of isOutList) {
                        for (let j of i.resourceList) {
                            if (!j.isOutResource && (j.dbSource == data.dbsource)) {
                                return 'display:block';
                            } else if (j.isOutResource && (j.dbSource == data.dbsource)) {
                                return 'display:none';
                            }
                        }
                    }
                },
                hideSave: function (data, index) {
                    if (data.tableName == "YQTFZWW_METADATA") {
                        return 'display:none';
                    }
                },
                tableName: function (data, index) {
                    return data.tableName ? data.tableName : data.outTableName;
                },
                ipAddress: function (data, index) {
                    if (data.tableName == 'YQTQBZX_METADATA') {
                        return '?sysId=' + data.sysID + '&type=1&tableCode=' + data.tableName;
                    } else if (data.tableName) {
                        return '?sysId=' + data.sysID + '&type=2&tableCode=' + data.tableName;
                    }
                }
            }
        }

        // 清除升序降序样式
        function clearSort() {
            $('.tbHeader button').removeClass('clickTop');
            $('.tbHeader button').removeClass('clickBottom');
        }
        $(function () {
            var code = base.getQueryParam('code');
            var urlData = JSON.parse(decodeURIComponent(base.getQueryParam('data')));
            shared.ajaxGet(config.getSearchItem, {}, function callback(res) {
                core.useTemplateAuto('selectArr', JSON.parse(res), {});
            })
            //    判断路由是否携带参数，判断是否展示高级检索框
            if (urlData) {
                //获取后台下拉列表
                if (urlData.adv) {
                    //切换显示
                    $('#advanceSearch').css('display', 'block');
                    $('#search_content').hide();
                    searchType = 'advanceSearch';
                } else {
                    $('#advanceSearch').css('display', 'none');
                    $('#search_content').show();
                    searchType = 'search';
                }
                $('#searchselect').val(urlData.searchTheam);
                //输入框的值
                $('#searchWord').val(urlData.searchStr);
                postTableData.searchKeyWord = urlData.searchTheam;
                postTableData.searchValue = urlData.searchStr;
            }
            // 请求表格数据
            // 左侧导航栏数据
            shared.ajaxGet(config.knowledgeGetIndex, {}, function callback(res) {
                isOutList = res;
                core.useTemplateAuto('menuData', res, {
                    showClose: function (data, index) {
                        if (data.resourceList && data.resourceList.length) {
                            return 'close hasChildren';
                        } else {
                            return 'noChildren'
                        }
                    }
                });
                if (code) {
                    code = JSON.stringify(code);
                    $('.asideMenu>.box .check').removeClass('check').addClass('nocheck');
                    $('p[ data-dbcode=' + code + ' ]').addClass('gray');
                    $('p[ data-dbcode=' + code + ' ]').parents('.children').siblings('p').toggleClass('open');
                    $('p[ data-dbcode=' + code + ' ]').parents('.children').css('display', 'block')
                    $('p[ data-dbcode=' + code + ' ]').parents('.children').siblings('p').children('.nocheck').removeClass('nocheck').addClass('check');
                    $('p[ data-dbcode=' + code + ' ]').children('.nocheck').removeClass('nocheck').addClass('check');
                }
                shared.ajaxGet(config.getIpAddress,{},function(res){
              for(var u=0;u<config.ip.length;u++){
                  if(res.indexOf(config.ip[u])==-1){
                   //影藏标签
                   $('li[ title="科研档案" ]').hide();
                  }else{
                      return;
                  }
              }
            })
                changeValue();
                pageData.tableData(config.complexSearch, postTableData, 'knowledgeTableData', 'test1', true, '#KnowledgeMention', render(), true, callBackPage);
            })
            // 全选
            $('#all').click(function () {
                $('.asideMenu>.box .nocheck').removeClass('nocheck').addClass('check');
                $(this).addClass('select');
                $('#not').removeClass('select')
            })
            // 取消
            $('#not').click(function () {
                $('.asideMenu>.box .check').removeClass('check').addClass('nocheck')
                $(this).addClass('select');
                $('#all').removeClass('select');

            })
            // 点击高级检索按钮出现高级检索框
            //高级，初级检索显示
            showAdvance();
            function showAdvance() {
                $('#advance').click(function () {
                   // $('#search_content').hide()
                   // $('#advanceSearch').css('display', 'block');
                    //searchType = 'advanceSearch';
                    window.location.href='http://10.89.145.250/KNS/brief/result.aspx?dbprefix=SYSTZK';
                })
                $('#preSearch').click(function () {
                    $('#advanceSearch').css('display', 'none');
                    $('#search_content').show();
                    searchType = 'search';
                })
            }
            // 点击检索事件
            $('#searchBtn').click(function () {
                goMultiSearch();
            })
            // 点击高级检索
            advance();
            // 高级检索
            function advance() {
                $('#firstSearch').click(function () {
                    // 获取年至时间
                    postTableData.beginDate = $('.date>#year').val();
                    postTableData.endDate = $('.date>#toDate').val();
                    postTableData.limitData = $("#createDate").find("option:selected").val();
                    postTableData.page = 1;
                    // 清除排序
                    postTableData.orderBySort = "",
                        postTableData.orderByValue = "",
                        postTableData.searchKeyWord = '';
                    postTableData.searchValue = ''
                    clearSort();
                    // 如果路由有参数
                    changeValue();
                    pageData.tableData(config.complexSearch, postTableData, 'knowledgeTableData', 'test1', true, '#KnowledgeMention', render(), true, callBackPage);
                })
            }
            //在结果中检索
            resultSearch();
            function resultSearch() {
                $('#searchResult').click(function () {
                    // 获取年至时间
                    postTableData.beginDate = $('.date>#year').val();
                    postTableData.endDate = $('.date>#toDate').val();
                    postTableData.limitData = $("#createDate").find("option:selected").val();
                    postTableData.page = 1;
                    // 清除排序
                    postTableData.orderBySort = "",
                        postTableData.orderByValue = "",
                        postTableData.searchKeyWord = '';
                    postTableData.searchValue = ''
                    postTableData.standConditionBoList = getMenu();
                    clearSort();

                    if (lastAdvancedSearchStr) {
                        postTableData.conditionSql = getAndVal();
                        if (postTableData.conditionSql) {
                            lastAdvancedSearchStr = lastAdvancedSearchStr + ' and ' + postTableData.conditionSql;
                        }
                        postTableData.conditionSql = lastAdvancedSearchStr;
                    } else {
                        //如果还没有搜索
                        lastAdvancedSearchStr = getAndVal();
                        if (!postTableData.conditionSql) {
                            postTableData.conditionSql = lastAdvancedSearchStr;
                        }
                    }
                    pageData.tableData(config.complexSearch, postTableData, 'knowledgeTableData', 'test1', true, '#KnowledgeMention', render(), true, callBackPage);
                })
            }
            // 点击表格里的升序降序
            sort();
            function sort() {
                $('.tbHeader .top').click(function () {
                    postTableData.page = 1;
                    postTableData.orderBySort = $(this).val();
                    postTableData.orderByValue = $(this).parent('div').siblings('span')[0].className;
                    //加上高亮样式
                    clearSort();
                    $(this).addClass('clickTop');
                    // 请求表格数据
                    pageData.tableData(config.complexSearch, postTableData, 'knowledgeTableData', 'test1', true, '#KnowledgeMention', render(), true);
                })
                $('.tbHeader .bottom').click(function () {
                    postTableData.page = 1;
                    postTableData.orderBySort = $(this).val();
                    postTableData.orderByValue = $(this).parent('div').siblings('span')[0].className;
                    //加上高亮样式
                    clearSort();
                    $(this).addClass('clickBottom');
                    // 请求表格数据
                    pageData.tableData(config.complexSearch, postTableData, 'knowledgeTableData', 'test1', true, '#KnowledgeMention', render(), true);
                })
            }
            //点击下载
            $('#knowledgeTable').click(function (e) {
               
                var dataDetail = {};
                dataDetail.dataSource = $(e.target).attr('data-dbname');
                dataDetail.tableCode = $(e.target).attr('data-tablename');
                dataDetail.sysId = $(e.target).attr('data-sysid');
                dataDetail.digitFileName = $(e.target).attr('data-digitfilename');
                if ($(e.target).hasClass('title')) {
                    if ($(e.target).attr('data-tablename') == 'YQTQBZX_METADATA') {
                        window.open('/resourseDetail.html?sysId=' + $(e.target).attr('data-sysid') + '&type=1&tableCode=' + $(e.target).attr('data-tablename'))
                        return;
                    }
                    else if($(e.target).attr('data-tablename') == 'YQTFZWW_METADATA'){
                        shared.ajaxPost(config.getFZWWDMETAID, {sysId:$(e.target).attr('data-sysid'),tableCode:$(e.target).attr('data-tablename')}, function callback(res) {
                            pageData.toWwqk(res)
                            return
                        })
                    } 
                    else if ($(e.target).attr('data-tablename') == 'YQTWWQK_METADATA') {
                        window.open('/magazineDetail.html?sysId=' + $(e.target).attr('data-sysid') + '&tableCode=' + $(e.target).attr('data-tablename'))
                        return;
                    }
                    for (let i of isOutList) {
                        if (!i.isOutResource && (i.dbCode == $(e.target).attr('data-tablename'))) {
                            window.open('/resourseDetail.html?sysId=' + $(e.target).attr('data-sysid') + '&type=2&tableCode=' + $(e.target).attr('data-tablename'))
                            return;
                        }
                        // 外部资源没有判断方式
                        for (let j of i.resourceList) {
                            if (i.isOutResource && (j.dbSource == $(e.target).attr('data-dbsource'))) {
                                pageData.isOutVisited($(e.target), config.insertView)
                                pageData.toOuter($(e.target))
                                return
                            }
                        }
                    }
                } else if ($(e.target).hasClass('save')) {
                    if (!shared.getCookie('token')) {
                        window.location.href = '/login.html'
                        return;
                    }
                     
                    for (let i of isOutList) {
                        if (!i.isOutResource && (i.dbCode == $(e.target).attr('data-tablename'))) {
                            //内部
                            pageData.savePop('#saveClassify', 'saveDocument','inner', $(e.target));
                            return;
                        } for (let j of i.resourceList) {
                            if (i.isOutResource && (j.dbSource == $(e.target).attr('data-dbsource'))) {
                                pageData.savePop('#saveClassify', 'saveDocument','out' , $(e.target));
                                return
                            }
                        }
                    }
                } else {
                    pageData.threePart(dataDetail, $(e.target))
                }
            })

        })

        // 获取值
        function changeValue() {
            if (searchType == 'advanceSearch') {
                postTableData.standConditionBoList = getMenu();
                postTableData.conditionSql = getAndVal();
                postTableData.searchKeyWord = '';
                postTableData.searchValue = '';
                lastAdvancedSearchStr = postTableData.conditionSql;
            }
            else if (searchType == 'search') {
                postTableData.standConditionBoList = getMenu();
                postTableData.conditionSql = '';
                postTableData.searchKeyWord = $("#searchselect").find("option:selected").val();
                postTableData.searchValue = $("#searchWord").val();
                if ($("#searchWord").val() && !base.patrn.test($("#searchWord").val())) {
                    pageData.InsertLog('知识服务', '检索', $("#searchWord").val());
                }

            }
        }
    </script>
</body>

</html>